#define  _CRT_SECURE_NO_WARNINGS
class Solution
{
public:
    void duplicateZeros(vector<int>& arr)
    {
        int dst = 0, cur = 0;
        while (cur < arr.size())
        {
            if (arr[dst++])
            {
                cur++;
            }
            else
            {
                cur += 2;
            }
        }
        if (cur >= arr.size())
        {
            dst--;
        }
        cur--;
        while (dst >= 0)
        {
            if (arr[dst] == 0)
            {
                if (cur == arr.size())
                {
                    arr[cur - 1] = 0;
                }
                else
                {
                    arr[cur] = arr[cur - 1] = 0;
                }
                cur -= 2;
            }
            else
            {
                arr[cur--] = arr[dst];
            }
            dst--;
        }
    }
};